// registerdialog.h
#ifndef REGISTERDIALOG_H
#define REGISTERDIALOG_H

#include <QDialog>
#include <QPropertyAnimation>
#include "client_network.h"

QT_BEGIN_NAMESPACE
namespace Ui { class RegisterDialog; }
QT_END_NAMESPACE

class RegisterDialog : public QDialog
{
    Q_OBJECT

public:
    explicit RegisterDialog(ClientNetwork *clientNet,QWidget *parent = nullptr);
    ~RegisterDialog();

    QString username() const;
    QString password() const;
    QString confirmPassword() const;

signals:
    void backToLoginRequested();  // 返回登录界面的信号
    void registerSuccess();

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void paintEvent(QPaintEvent *event) override;

private slots:
    void onRegisterClicked();
    void onBackToLoginClicked();
    void animateButton(QWidget *button);
    void handleRegisterResponse(const QJsonObject &response);

private:
    Ui::RegisterDialog *ui;
    QPoint m_dragPosition;
    ClientNetwork *m_clientNetwork;
    QPropertyAnimation *createButtonAnimation(QWidget *target);
    bool validatePhoneNumber(const QString &phone);
};

#endif // REGISTERDIALOG_H
